{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0",
   "metadata": {},
   "source": [
    "<a href=\"https://githubtocolab.com/gee-community/geemap/blob/master/docs/notebooks/116_land_cover_timeseries.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open in Colab\"/></a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# !pip install geemap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import ee\n",
    "import geemap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "Map.add_basemap(\"HYBRID\")\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set the region of interest by simply drawing a polygon on the map\n",
    "region = Map.user_roi\n",
    "if region is None:\n",
    "    region = ee.Geometry.BBox(-89.7088, 42.9006, -89.0647, 43.2167)\n",
    "\n",
    "Map.centerObject(region)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set the date range\n",
    "start_date = \"2017-01-01\"\n",
    "end_date = \"2021-12-31\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6",
   "metadata": {},
   "source": [
    "The `return_type` can be `hillshade`, `visualize`, `class`, or `probability`. If you want to use the resulting images for further analysis, you should use `class`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7",
   "metadata": {},
   "outputs": [],
   "source": [
    "images = geemap.dynamic_world_timeseries(\n",
    "    region, start_date, end_date, return_type=\"class\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8",
   "metadata": {},
   "outputs": [],
   "source": [
    "vis_params = {\n",
    "    \"min\": 0,\n",
    "    \"max\": 8,\n",
    "    \"palette\": [\n",
    "        \"#419BDF\",\n",
    "        \"#397D49\",\n",
    "        \"#88B053\",\n",
    "        \"#7A87C6\",\n",
    "        \"#E49635\",\n",
    "        \"#DFC35A\",\n",
    "        \"#C4281B\",\n",
    "        \"#A59B8F\",\n",
    "        \"#B39FE1\",\n",
    "    ],\n",
    "}\n",
    "Map.addLayer(images.first(), vis_params, \"First image\")\n",
    "Map.add_legend(title=\"Dynamic World Land Cover\", builtin_legend=\"Dynamic_World\")\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map.ts_inspector(images, left_vis=vis_params, date_format=\"YYYY\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "Map.add_basemap(\"HYBRID\")\n",
    "Map.centerObject(region)\n",
    "\n",
    "images = geemap.dynamic_world_timeseries(\n",
    "    region, start_date, end_date, return_type=\"hillshade\"\n",
    ")\n",
    "Map.ts_inspector(images, date_format=\"YYYY\")\n",
    "Map.add_legend(title=\"Dynamic World Land Cover\", builtin_legend=\"Dynamic_World\")\n",
    "\n",
    "Map"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "11",
   "metadata": {},
   "source": [
    "![](https://i.imgur.com/5DGOuTC.png)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
